package com.pb.camera.utils;

import com.tutk.IOTC.AVIOCTRLDEFs;

import java.util.Calendar;

/**
 * Created by Administrator on 2016/3/31 0031.
 */
public class TimeUtils {
    public static long getZeroClockStamp(Calendar calendar){
        int hour = calendar.get(Calendar.HOUR_OF_DAY) - 8;
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        return calendar.getTimeInMillis()/1000 - second - minute*60 - hour*3600;
    }
    //得到相对时间戳
    public static long getTimeMills(int hour,int minute,int second){
        long timeMills = (hour*3600+minute*60+second)*1000;
        return timeMills;
    }

    //以秒为单位返回 Record 事件和 指定calender之间的 绝对值时间差
    public static int calculateTimeDiff(Calendar calendar, AVIOCTRLDEFs.SAvEvent closestEvent) {
        int timeDiff = (calendar.get(Calendar.HOUR_OF_DAY) - (closestEvent.utctime.hour+8)) * 3600;
        timeDiff += (calendar.get(Calendar.MINUTE) - closestEvent.utctime.minute)*60;
        timeDiff += (calendar.get(Calendar.SECOND) - closestEvent.utctime.second);
        return Math.abs(timeDiff);
    }
}
